<template>
	<view>
		<view class='recombox' v-if='recomatr'>
			<view class='recomTitle' v-if="base_tag==0">TA是你的推荐人吗</view>
			<view class='recomTitle' v-if="base_tag==1">您已拥有推广人</view>
			<image class='recomactive' :src="uInfo.avatar"></image>
			<view class='recomName'>{{uInfo.username}}</view>
			<view class='recomcenter'>
				<view class='recomer'>推荐码</view>
				<input v-model='uid' :disabled='true' placeholder="请输入推荐码">
			</view>
			<view class='recomyou' @click='open'>
				推广人有误？手动填写
			</view>
			<view class='mobox' v-if='base_tag==0'>
				<view class='moquery' @click="base_tag=1">是</view>
				<view class='moesc' @click="uni.navigateBack()">否</view>
			</view>
			<view class='shouquery' v-if='base_tag==1' @click="toLogin">确认</view>
		</view>
		<uni-popup ref="popupRef" type="center" :mask-click="false" :animation="false">
			<view class='popupbox'>
				<view class='popupcentar'>
					填写推广码
				</view>
				<view class='recomcenter'>
					<view class='recomer'>推荐码</view>
					<input v-model='uid' placeholder="请输入推荐码">
				</view>
				<view class='recomyou' style='color:#FC724C;'>
					<span v-if='new_remind'>当前推广人不存在</span>
				</view>
				<view class='mobox' style='margin-top:64rpx;'>
					<view class='moquery' @click='query'>提交</view>
					<view class='moesc' @click="close">取消</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getUserInandRece
	}
	from '../../api/marketing/promotion';
	const app = getApp();
	export default {
		data() {
			return {
				base_url: app.globalData.imgUrl,
				base_tag: 0, //0默认  1 二次确认 
				uid: '', //推广人id
				new_remind: false, //推广不存在提醒
				recomatr: true, //修改推广人是弹框下不显示
				reco_name: '刘小二',
				// 推广人信息
				uInfo:{
					
				}
			}
		},
		onLoad(options) {
			console.log('路径携带参数',options)
			if(options.uid){
				this.uid=options.uid
			    this.menber()
			}
		},
		methods: {
			menber() {
				getUserInandRece(this.uid).then(res => {
					console.log('这是推广人信息',res)
					this.uInfo=res.data
				})
			},
			close() {
				this.$refs.popupRef.close()
				this.recomatr = true;
			},
			open() {
				this.recomatr = false;
				this.$refs.popupRef.open('top')
			},
			query() {
				getUserInandRece(this.uid).then(res => {
					if(res.data.msg=="当前推广人不存在"){
						this.new_remind=true
					}else{
						this.new_remind=false
						this.close()
					}
				})
			},
			toLogin(){
				//邀请类型 1邀请 2推广 3自己注册
				uni.setStorageSync('inviterId',2)
				//推广人id
				promoterId: uni.setStorageSync('promoterId',this.uid)
				uni.reLaunch({
					url: '/pages/index/index'
				})
			}
		}
	}
</script>

<style scoped>
	.recombox {
		padding: 64rpx;
		display: flex;
		flex-direction: column;
		background-color: #fff;
	}

	.recomTitle {
		font-size: 34rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: 400;
		color: #303133;
		margin: 80rpx 0 60rpx;
		text-align: center;
	}

	.recomName {
		font-size: 34rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: 400;
		color: #606266;
		margin: 20rpx 0 120rpx;
		text-align: center;
	}

	.recomactive {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		margin: 0 auto;
	}

	.recomer {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 400;
		color: #606266;
		margin-right: 40rpx;
	}

	input {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 400;
		color: #303133;
	}

	.recomyou {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 400;
		color: #6DB12E;
		padding-top: 24rpx;
		border-top: 1rpx solid #DCDFE6;
	}

	.recomcenter {
		margin-bottom: 20rpx;
		display: flex;
	}

	.shouquery {
		width: 622rpx;
		height: 88rpx;
		background: #6DB12E;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 30rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: 400;
		text-align: center;
		color: #FFFFFF;
		line-height: 88rpx;
		margin-top: 100rpx;
	}

	.mobox {
		display: flex;
		justify-content: space-between;
		margin-top: 50px;
	}

	.mobox view {
		width: 299rpx;
		height: 88rpx;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 30rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: 400;
		text-align: center;
		line-height: 88rpx;
	}

	.moquery {
		background: #6DB12E;
		border: 1rpx solid #6DB12E;
		color: #FFFFFF;
	}

	.moesc {
		border: 1rpx solid #909399;
		color: #909399;
	}

	.popupbox {
		width: 638rpx;
		height: 423rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		position: fixed;
		left: 50%;
		top: 30vh;
		transform: translateX(-50%);
		padding: 0 32rpx;
	}

	.popupcentar {
		font-size: 34rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: 400;
		color: #303133;
		text-align: center;
		margin: 28rpx 0;
	}
</style>